Conditions | 2 |
Paths | 2 |
Total Lines | 39 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | 'use strict' |
||
3 | module.exports = (input, callback) => { |
||
4 | const mqtt = require('mqtt') |
||
5 | const validate = require('./validate') |
||
6 | const configuration = require('./configuration') |
||
7 | let error = null |
||
8 | let output = null |
||
9 | |||
10 | validate.sourceConfiguration(input, (validatedInput, thrownError) => { |
||
11 | input = validatedInput |
||
12 | error = thrownError |
||
13 | }) |
||
14 | |||
15 | // Send MQTT |
||
16 | if ( !error ) { |
||
17 | let configurationMqtt = configuration.mqtt(input) |
||
18 | let client = mqtt.connect(input.source.url, configurationMqtt) |
||
19 | let version = null |
||
20 | |||
21 | client.on('connect', () => { |
||
22 | let topic = input.source.prefix + '/' + process.env.BUILD_TEAM_NAME + '/' + process.env.BUILD_PIPELINE_NAME |
||
23 | client.subscribe(topic, (errorConnection) => { |
||
24 | if ( !errorConnection ) { |
||
25 | client.on('message', (topic, message) => { |
||
26 | version = message.toString() |
||
27 | client.end() |
||
28 | }) |
||
29 | } else { |
||
30 | error = errorConnection |
||
31 | } |
||
32 | }) |
||
33 | }) |
||
34 | |||
35 | output = [ |
||
36 | {'ref': version} |
||
37 | ] |
||
38 | } |
||
39 | |||
40 | callback(error, output) |
||
41 | } |
||
42 |